//
//  CComEditView.m
//  HCHK_iphone
//
//  Created by yilong zhang on 12-1-5.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "CComEditView.h"

//====================================================================================================================

@implementation CellData

@synthesize m_Com;
@synthesize m_fHeight;

-(id)initWithCom:(CCommentary*)com Height:(CGFloat)height
{
    self = [super init];
    if (self)
    {
        self.m_Com     = com;
        self.m_fHeight = height;
    }
    return self;
}

-(void)dealloc
{
    self.m_Com = nil;
    
    [super dealloc];
}

@end

//====================================================================================================================

@implementation CWriteView

@synthesize delegate;
@synthesize m_BackView;
@synthesize m_Title;
@synthesize m_TextView;
@synthesize m_Icon;
@synthesize m_Shadow;
@synthesize m_Stars;
@synthesize m_ComitBtn;
@synthesize m_CancelBtn;

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
    }
    
    return self;
}

-(void)InitComWriteView
{
    m_Icon.layer.masksToBounds = YES;
    m_Icon.layer.cornerRadius  = 23;
    m_Icon.image = [UIImage imageNamed:@"dicon.png"];
    
    m_Shadow.layer.cornerRadius = 23;
    m_Shadow.layer.shadowOffset = CGSizeMake(2, 2);
    m_Shadow.layer.shadowColor  = [[UIColor blackColor] CGColor];
    m_Shadow.layer.shadowOpacity= 0.8;
    
    /*UIImageView *star = nil;
    CGFloat fx = m_Stars.frame.size.width/5;
    for (int i=0; i<5; i++)
    {
        star = [[UIImageView alloc] initWithFrame:CGRectMake(i*fx, 0, fx, m_Stars.frame.size.height)];
        [m_Stars addSubview:star];
        [star release];
    }

    [self SetLightStarNum:4];*/
    m_Stars = [[CStarts alloc] initWithFrame:CGRectMake(209, 56, 100, 20) Num:5 StarSize:CGSizeMake(20, 20)];
    [self addSubview:m_Stars];
    [m_Stars release];
}

-(void)SetLightStarNum:(int)num
{
    [m_Stars SetLightStartWithNum:num];
    return;
    
    if (num > 5)
        num = 5;
    
    UIImageView *star = nil;
    for (int i=0; i<num; i++)
    {
        star = [[m_Stars subviews] objectAtIndex:i];
        [star setImage:[UIImage imageNamed:@"favorite-yellow.png"]];
    }
}

-(void)ResetStars
{
    [m_Stars ResetStart];
    return;
    
    UIImageView *star = nil;
    for (int i=0; i<5; i++)
    {
        star = [[m_Stars subviews] objectAtIndex:i];
        [star setImage:[UIImage imageNamed:@"favorite-gray.png"]];
    }
}

-(IBAction)OnButtonDown:(UIButton*)sender
{
    [delegate DidWriteViewButtonClicked:sender Object:m_TextView.text];
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    textView.text = nil;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = 1;
        [delegate DidWriteViewButtonClicked:btn Object:m_TextView.text];
        return NO;
    }
    else if ([textView.text length] > 140)
    {
        textView.text = [textView.text substringToIndex:139];
        return NO;
    }
    else if (0 == range.length)
    {
        return YES;
    }
    else {;}
    
    return YES;
}

@end

//====================================================================================================================

@implementation CComEditView

@synthesize delegate;
@synthesize m_TopBar;
@synthesize m_TopInfo;
@synthesize m_PdtName;
@synthesize m_ResName;
@synthesize m_ResAddr;
@synthesize m_PubName;
@synthesize m_SumContent;
@synthesize m_StarsPanel;
@synthesize m_SharePanel;
@synthesize m_Drawer;
@synthesize m_Local;
@synthesize m_Distance;
@synthesize m_AddCom;
@synthesize m_Scroll;
@synthesize m_Image;
@synthesize m_Icon;
@synthesize m_Table;
@synthesize m_FontHeight;
@synthesize m_Product;
@synthesize m_DisData;
@synthesize m_BtnPanel;
@synthesize m_Share;
@synthesize m_More;
@synthesize m_Addr;
@synthesize m_Write;
@synthesize m_PreItem;

@synthesize m_Pinglun;
@synthesize m_ComFinishBtn;
@synthesize m_SameName;
@synthesize m_SameRes;
@synthesize m_DelBtn;
@synthesize m_NiceBtn;
@synthesize m_wantBtn;

@synthesize m_SuvView;
@synthesize m_SubImgs;

@synthesize m_PreSubImgPanel;
@synthesize m_PreSubImg;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // Initialization code
        //self.backgroundColor = [CMainPageCtrl DefaultMainPageCtrl].view.backgroundColor;//[UIColor colorWithRed:0.964 green:0.968 blue:0.949 alpha:1.0];
        m_DisData = [NSMutableArray array];
        [m_DisData retain];
        
        UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        bg.image = [UIImage imageNamed:@"appbg.jpg"];
        [self addSubview:bg];
        [bg release];
        
        //topbarview
        m_TopBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 51)];
        m_TopBar.backgroundColor = [UIColor clearColor];
        [self addSubview:m_TopBar];
        [m_TopBar release];
        
        UIImageView *backbg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, m_TopBar.frame.size.width, 51)];
        backbg.image = [UIImage imageNamed:@"barbg.png"];
        //backbg.layer.shadowOffset = CGSizeMake(0, 1);
        //backbg.layer.shadowColor  = [[UIColor blackColor] CGColor];
        //backbg.layer.shadowOpacity= 0.8;
        [m_TopBar addSubview:backbg];
        [backbg release];
        
        UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        backbtn.frame = CGRectMake(10, 6, 43, 38);
        [backbtn setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
        backbtn.tag = 0;
        [backbtn addTarget:self action:@selector(OnBackButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_TopBar addSubview:backbtn];
        
        m_Pinglun = [UIButton buttonWithType:UIButtonTypeCustom];
        m_Pinglun.frame = CGRectMake(self.frame.size.width-80, 6, 70, 38);
        m_Pinglun.tag = 0;
        [m_Pinglun setBackgroundImage:[UIImage imageNamed:@"pingjia.png"] forState:UIControlStateNormal];
        [m_Pinglun addTarget:self action:@selector(OnPingJiaButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_TopBar addSubview:m_Pinglun];
        
        m_ComFinishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        m_ComFinishBtn.frame = CGRectMake(self.frame.size.width-80, 6, 70, 39);
        m_ComFinishBtn.tag = 1;
        m_ComFinishBtn.alpha = 0.0;
        [m_ComFinishBtn setBackgroundImage:[UIImage imageNamed:@"commitcom.png"] forState:UIControlStateNormal];
        [m_ComFinishBtn addTarget:self action:@selector(OnPingJiaButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_TopBar addSubview:m_ComFinishBtn];
        
        UIImageView *title = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hchk.png"]];
        title.frame = CGRectMake(0, 0, 110, 36);
        title.center= CGPointMake(m_TopBar.frame.size.width/2, m_TopBar.frame.size.height/2-2);
        [m_TopBar addSubview:title];
        [title release];
        
        /*topinfoview
        m_TopInfo = [[UIView alloc] initWithFrame:CGRectMake(0, backbg.frame.size.height, self.frame.size.width, 75)];
        [self addSubview:m_TopInfo];
        [m_TopInfo release];
        
        UIView *infobg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m_TopInfo.frame.size.width, m_TopInfo.frame.size.height-8)];
        infobg.backgroundColor = [UIColor colorWithRed:0.964 green:0.968 blue:0.949 alpha:1.0];
        infobg.alpha = 0.9;
        [m_TopInfo addSubview:infobg];
        [infobg release];
        
        UIImageView *cross = [[UIImageView alloc] initWithFrame:CGRectMake(15, 67, 25, 15)];
        cross.image = [UIImage imageNamed:@"topinfocross.png"];
        cross.alpha = 0.9;
        [m_TopInfo addSubview:cross];
        [cross release];*/
        
        //name
        m_PdtName = [[UILabel alloc] initWithFrame:CGRectMake(5, m_TopBar.frame.size.height-2, self.frame.size.width-10, 25)];
        //m_PdtName.font = [UIFont boldSystemFontOfSize:20];
        m_PdtName.font = [UIFont fontWithName:@"迷你简准圆" size:20];
        m_PdtName.textColor = [UIColor brownColor];
        m_PdtName.backgroundColor = [UIColor clearColor];
        [self addSubview:m_PdtName];
        [m_PdtName release];
        
        //image
        UIImageView *imgback = [[UIImageView alloc] initWithFrame:CGRectMake(0, m_TopBar.frame.size.height+20, 160, 200)];
        imgback.image = [UIImage imageNamed:@"p-cover.png"];
        [self addSubview:imgback];
        [imgback release];
        
        m_Image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 16, 141, 165)];
        m_Image.layer.masksToBounds = YES;
        m_Image.layer.cornerRadius = 6;
        m_Image.backgroundColor = [UIColor clearColor];
        m_Image.image = [UIImage imageNamed:@"1.jpg"];
        [imgback addSubview:m_Image];
        [m_Image release];
        
        UIImageView *part = [[UIImageView alloc] initWithFrame:CGRectMake(2, m_TopBar.frame.size.height+17, 30, 30)];
        part.image = [UIImage imageNamed:@"part-up.png"];
        [self addSubview:part];
        [part release];
        
        part = [[UIImageView alloc] initWithFrame:CGRectMake(imgback.frame.origin.x+imgback.frame.size.width-30, imgback.frame.origin.y+imgback.frame.size.height-25, 30, 25)];
        part.image = [UIImage imageNamed:@"part-down.png"];
        [self addSubview:part];
        [part release];
        
        //头像
        UIView *iconshadow = [[UIView alloc] initWithFrame:CGRectMake(imgback.frame.origin.x+imgback.frame.size.width+5, imgback.frame.origin.y+85, 50, 50)];
        iconshadow.backgroundColor = [UIColor blackColor];
        iconshadow.layer.cornerRadius = 25;
        iconshadow.layer.shadowOffset = CGSizeMake(3, 3);
        iconshadow.layer.shadowColor  = [[UIColor blackColor] CGColor];
        iconshadow.layer.shadowOpacity= 0.8;
        [self addSubview:iconshadow];
        
        m_Icon = [[UIImageView alloc] initWithFrame:iconshadow.frame];
        m_Icon.image = [UIImage imageNamed:@"dicon.png"];
        m_Icon.layer.masksToBounds = YES;
        m_Icon.layer.cornerRadius  = 25;
        [self addSubview:m_Icon];
        [m_Icon release];
        
        //发布者昵称
        m_PubName = [[UILabel alloc] initWithFrame:CGRectMake(m_Icon.frame.origin.x+m_Icon.frame.size.width+7, m_Icon.frame.origin.y, 86, 40)];
        m_PubName.textColor = [UIColor whiteColor];
        m_PubName.backgroundColor = [UIColor clearColor];
        m_PubName.font = [UIFont systemFontOfSize:14];
        m_PubName.text = @"美食发布者的美食发布者的美食发布者的美食发布者的";
        m_PubName.numberOfLines = 2;
        [self addSubview:m_PubName];
        [m_PubName release];
        
        //描述
        m_SumContent = [[UILabel alloc] initWithFrame:CGRectMake(imgback.frame.origin.x+imgback.frame.size.width+5, m_Icon.frame.origin.y-50, 150, 45)];
        m_SumContent.numberOfLines = 3;
        m_SumContent.font = [UIFont systemFontOfSize:12];
        m_SumContent.textColor = [UIColor whiteColor];
        m_SumContent.backgroundColor = [UIColor clearColor];
        m_SumContent.text = @"";
        [self addSubview:m_SumContent];
        [m_SumContent release];
        
        //星星
        /*m_StarsPanel = [[UIView alloc] initWithFrame:CGRectMake(m_SumContent.frame.origin.x, m_PdtName.frame.origin.y+m_PdtName.frame.size.height+5, m_SumContent.frame.size.width, 20)];
        m_StarsPanel.backgroundColor = [UIColor clearColor];
        [self addSubview:m_StarsPanel];
        [m_StarsPanel release];
        
        UIImageView *star = nil;
        CGFloat fx = m_StarsPanel.frame.size.width/5;
        for (int i=0; i<5; i++)
        {
            star = [[UIImageView alloc] initWithFrame:CGRectMake(i*fx, 0, 20, 20)];
            star.image = [UIImage imageNamed:@"favorite-gray.png"];
            [m_StarsPanel addSubview:star];
            [star release];
        }*/
        
        m_StarsPanel = [[CStarts alloc] initWithFrame:CGRectMake(m_SumContent.frame.origin.x, m_PdtName.frame.origin.y+m_PdtName.frame.size.height+5, 100, 20) Num:5 StarSize:CGSizeMake(20, 20)];
        m_StarsPanel.userInteractionEnabled = NO;
        [self addSubview:m_StarsPanel];
        [m_StarsPanel release];
        
        //分享
        m_Share = [UIButton buttonWithType:UIButtonTypeCustom];
        m_Share.tag = 0;
        m_Share.frame = CGRectMake(self.frame.size.width-95, imgback.frame.origin.y+imgback.frame.size.height-33, 85, 30);
        [m_Share setBackgroundImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
        [m_Share addTarget:self action:@selector(OnAttentionSelected:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:m_Share];
        
        //收藏
        m_NiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        m_NiceBtn.tag = 1;
        m_NiceBtn.frame = CGRectMake(self.frame.size.width-95, imgback.frame.origin.y+imgback.frame.size.height-73, 85, 30);
        [m_NiceBtn setBackgroundImage:[UIImage imageNamed:@"love.png"] forState:UIControlStateNormal];
        [m_NiceBtn addTarget:self action:@selector(OnFavoriteButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:m_NiceBtn];
        
        //points line
        UIImageView *pline = [[UIImageView alloc] initWithFrame:CGRectMake(0, imgback.frame.origin.y+imgback.frame.size.height+55, self.frame.size.width, 2)];
        pline.image = [UIImage imageNamed:@"cutline.png"];
        [self addSubview:pline];
        [pline release];
        
        //resname
        m_ResName = [[UILabel alloc] initWithFrame:CGRectMake(2, imgback.frame.origin.y+imgback.frame.size.height, self.frame.size.width-4, 25)];
        m_ResName.font = [UIFont systemFontOfSize:11];
        m_ResName.backgroundColor = [UIColor clearColor];
        m_ResName.numberOfLines = 2;
        m_ResName.text = @"";
        m_ResName.textColor = [UIColor whiteColor];
        [self addSubview:m_ResName];
        [m_ResName release];
        
        m_ResAddr = [[UILabel alloc] initWithFrame:CGRectMake(2, m_ResName.frame.origin.y+m_ResName.frame.size.height+3, m_ResName.frame.size.width, 25)];
        m_ResAddr.font = [UIFont systemFontOfSize:11];
        m_ResAddr.backgroundColor = [UIColor clearColor];
        m_ResAddr.numberOfLines = 2;
        m_ResAddr.text = @"";
        m_ResAddr.textColor = [UIColor whiteColor];
        [self addSubview:m_ResAddr];
        [m_ResAddr release];
        
        /*local icon
        m_Local = [[UIImageView alloc] initWithFrame:CGRectMake(m_ResAddr.frame.origin.x+m_ResAddr.frame.size.width, m_ResAddr.frame.origin.y, 8, 12)];
        m_Local.image = [UIImage imageNamed:@"pin.png"];
        [m_TopInfo addSubview:m_Local];
        [m_Local release];
        
        /distance
        m_Distance = [[UILabel alloc] initWithFrame:CGRectMake(m_Local.frame.origin.x+m_Local.frame.size.width, m_ResAddr.frame.origin.y, 55, 15)];
        m_Distance.font = [UIFont italicSystemFontOfSize:10];
        m_Distance.backgroundColor = [UIColor clearColor];
        m_Distance.textAlignment = UITextAlignmentLeft;
        m_Distance.textColor = [UIColor colorWithRed:0.333 green:0.333 blue:0.333 alpha:1.0];
        m_Distance.text = @"0km";
        [m_TopInfo addSubview:m_Distance];
        [m_Distance release];
        
        //add commentry
        m_AddCom = [UIButton buttonWithType:UIButtonTypeCustom];
        m_AddCom.tag = 1;
        m_AddCom.frame = CGRectMake(m_TopInfo.frame.size.width-70, 5, 70, 55);
        [m_AddCom addTarget:self action:@selector(OnBackButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_AddCom setBackgroundImage:[UIImage imageNamed:@"writepj.png"] forState:UIControlStateNormal];
        [m_TopInfo addSubview:m_AddCom];*/
        
        /*attention
        m_SameRes = [UIButton buttonWithType:UIButtonTypeCustom];
        m_SameRes.frame = CGRectMake(self.frame.size.width-94, m_TopBar.frame.size.height+m_TopInfo.frame.size.height-8, 84, 30);
        [m_SameRes setBackgroundImage:[UIImage imageNamed:@"sameres.png"] forState:UIControlStateNormal];
        [m_SameRes addTarget:self action:@selector(OnAttenButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        m_SameRes.tag = 1;
        [self insertSubview:m_SameRes belowSubview:m_TopInfo];
        
        m_SameName = [UIButton buttonWithType:UIButtonTypeCustom];
        m_SameName.frame = CGRectMake(m_SameRes.frame.origin.x-77, m_SameRes.frame.origin.y, 84, 30);
        [m_SameName setBackgroundImage:[UIImage imageNamed:@"samefood.png"] forState:UIControlStateNormal];
        [m_SameName addTarget:self action:@selector(OnAttenButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        m_SameName.tag = 2;
        [self insertSubview:m_SameName belowSubview:m_TopInfo];
        
        //评价区域
        m_DelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        m_DelBtn.frame = CGRectMake(40, m_Image.frame.origin.y+m_Image.frame.size.height+10, 80, 35);
        [m_DelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        m_DelBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        [m_DelBtn setTitle:@"好吃 0" forState:UIControlStateNormal];
        m_DelBtn.tag = 3;
        [m_DelBtn setBackgroundImage:[UIImage imageNamed:@"delious.png"] forState:UIControlStateNormal];
        [m_DelBtn addTarget:self action:@selector(OnPingJiaButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_Scroll addSubview:m_DelBtn];
        
        m_NiceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        m_NiceBtn.frame = CGRectMake(m_DelBtn.frame.origin.x+80, m_DelBtn.frame.origin.y, 80, 35);
        [m_NiceBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        m_NiceBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        [m_NiceBtn setTitle:@"好看 0" forState:UIControlStateNormal];
        m_NiceBtn.tag = 4;
        [m_NiceBtn setBackgroundImage:[UIImage imageNamed:@"nice.png"] forState:UIControlStateNormal];
        [m_NiceBtn addTarget:self action:@selector(OnPingJiaButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_Scroll addSubview:m_NiceBtn];
        
        m_wantBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        m_wantBtn.frame = CGRectMake(m_NiceBtn.frame.origin.x+80, m_DelBtn.frame.origin.y, 80, 35);
        [m_wantBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        m_wantBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        [m_wantBtn setTitle:@"想吃 0" forState:UIControlStateNormal];
        m_wantBtn.tag = 5;
        [m_wantBtn setBackgroundImage:[UIImage imageNamed:@"want.png"] forState:UIControlStateNormal];
        [m_wantBtn addTarget:self action:@selector(OnPingJiaButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_Scroll addSubview:m_wantBtn];*/
        
        //scrollview
        m_Scroll = [[UIScrollView alloc] initWithFrame:CGRectMake((self.frame.size.width-306)/2, pline.frame.origin.y+5, 306, self.frame.size.height-pline.frame.origin.y-35)];
        m_Scroll.showsVerticalScrollIndicator = NO;
        m_Scroll.scrollEnabled = NO;
        m_Scroll.delegate = self;
        m_Scroll.contentSize = CGSizeMake(m_Scroll.frame.size.width, m_Scroll.frame.size.height+1);
        m_Scroll.backgroundColor = [UIColor clearColor];
        [self addSubview:m_Scroll];
        [m_Scroll release];
         
        //list of commentires
        m_Table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, m_Scroll.frame.size.width, 0)];
        m_Table.scrollEnabled = NO;
        m_Table.separatorStyle= UITableViewCellSeparatorStyleNone;
        m_Table.delegate = self;
        m_Table.dataSource=self;
        m_Table.backgroundColor = [UIColor clearColor];
        [m_Scroll addSubview:m_Table];
        [m_Table release];
        
        //btnpanel;
        /*m_BtnPanel = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width-160, m_AttenBtn.frame.origin.y+m_AttenBtn.frame.size.height, 150, 130)];
        m_BtnPanel.backgroundColor = [UIColor clearColor];
        m_BtnPanel.alpha = 0.0;
        [self addSubview:m_BtnPanel];
        [m_BtnPanel release];
        
        UIView *popback = [[UIView alloc] initWithFrame:CGRectMake(0, 10, m_BtnPanel.frame.size.width, m_BtnPanel.frame.size.height-10)];
        popback.alpha = 0.8;
        popback.backgroundColor = [UIColor blackColor];
        popback.layer.cornerRadius = 15;
        [m_BtnPanel addSubview:popback];
        [popback release];
        
        CGFloat fheight = popback.frame.size.height/3;
        //people
        
        //food
        m_More = [UIButton buttonWithType:UIButtonTypeCustom];
        m_More.tag = 1;
        m_More.frame = CGRectMake(0, fheight+10, popback.frame.size.width, fheight);
        m_More.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        [m_More setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [m_More setTitleColor:[UIColor colorWithRed:0.447 green:0.501 blue:0.137 alpha:1.0] forState:UIControlStateHighlighted];
        //[m_More setBackgroundImage:[UIImage imageNamed:@"6.png"] forState:UIControlStateNormal];
        [m_More addTarget:self action:@selector(OnAttentionSelected:) forControlEvents:UIControlEventTouchUpInside];
        [m_More setTitle:@"关注这个人" forState:UIControlStateNormal];
        [m_BtnPanel addSubview:m_More];
        
        //address
        m_Addr = [UIButton buttonWithType:UIButtonTypeCustom];
        m_Addr.tag = 2;
        m_Addr.frame = CGRectMake(0, 2*fheight+10, popback.frame.size.width, fheight);
        m_Addr.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        [m_Addr setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [m_Addr setTitleColor:[UIColor colorWithRed:0.447 green:0.501 blue:0.137 alpha:1.0] forState:UIControlStateHighlighted];
        //[m_Addr setBackgroundImage:[UIImage imageNamed:@"6.png"] forState:UIControlStateNormal];
        [m_Addr addTarget:self action:@selector(OnAttentionSelected:) forControlEvents:UIControlEventTouchUpInside];
        [m_Addr setTitle:@"关注这个地方" forState:UIControlStateNormal];
        [m_BtnPanel addSubview:m_Addr];*/
        
        //write commentry
        m_Write = [[[NSBundle mainBundle] loadNibNamed:@"CWriteCom" owner:self options:nil] objectAtIndex:0];
        m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y-m_Write.frame.size.height);
        [m_Write InitComWriteView];
        m_Write.delegate = self;
        /*m_Write.m_TextView.backgroundColor = infobg.backgroundColor;
        m_Write.m_TextView.layer.cornerRadius = 5;
        m_Write.m_TextView.layer.borderColor  = [[UIColor lightGrayColor] CGColor];
        m_Write.m_TextView.layer.borderWidth  = 1;
        m_Write.m_TextView.layer.shadowOffset = CGSizeMake(2, 2);
        m_Write.m_TextView.layer.shadowColor  = [[UIColor blackColor] CGColor];
        m_Write.m_TextView.layer.shadowOpacity= 1.0;
        m_Write.m_TextView.clipsToBounds = NO;*/
        [self addSubview:m_Write];
        
        m_SuvView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height-40, self.frame.size.width, ICON_HEIGHT+40)];
        [self addSubview:m_SuvView];
        [m_SuvView release];
        
        UIImageView *tmp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, m_SuvView.frame.size.width, ICON_HEIGHT)];
        tmp.image = [UIImage imageNamed:@"appbg.jpg"];
        [m_SuvView addSubview:tmp];
        [tmp release];
        
        m_SubImgs = [[CGalleryView alloc] initWithFrame:CGRectMake(0, 40, m_SuvView.frame.size.width, ICON_HEIGHT) ItemSize:CGSizeMake(ICON_WIDTH, ICON_HEIGHT) Horizontal:YES];
        m_SubImgs.m_delegate = self;
        //m_SubImgs.backgroundColor = [UIColor lightGrayColor];
        [m_SuvView addSubview:m_SubImgs];
        [m_SubImgs release];
        
        //drawer
        m_Drawer = [UIButton buttonWithType:UIButtonTypeCustom];
        m_Drawer.tag = 2;
        m_Drawer.frame = CGRectMake((m_SuvView.frame.size.width-150)/2, 0, 150, 40);
        [m_Drawer setBackgroundImage:[UIImage imageNamed:@"button-more.png"] forState:UIControlStateNormal];
        [m_Drawer addTarget:self action:@selector(OnDrawerDown:) forControlEvents:UIControlEventTouchUpInside];
        [m_SuvView addSubview:m_Drawer];
        
        /*CGalleyItem *item1 = [[CGalleyItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        CGalleyItem *item2 = [[CGalleyItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        CGalleyItem *item3 = [[CGalleyItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        CGalleyItem *item4 = [[CGalleyItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        CGalleyItem *item5 = [[CGalleyItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        CGalleyItem *item6 = [[CGalleyItem alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
        [m_SubImgs SetItems:[NSArray arrayWithObjects:item1, item2, item3, item4, item5, item6, nil] Item:nil];*/
        
        [self bringSubviewToFront:m_TopBar];
        [self SetUpSharePanel];
        
        m_PreSubImgPanel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        [self addSubview:m_PreSubImgPanel];
        m_PreSubImgPanel.alpha = 0.0;
        [m_PreSubImgPanel release];
        
        UIView *temp = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m_PreSubImgPanel.frame.size.width, m_PreSubImgPanel.frame.size.height)];
        temp.backgroundColor = [UIColor blackColor];
        temp.alpha = 0.7;
        [m_PreSubImgPanel addSubview:temp];
        [temp release];
        
        m_PreSubImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];
        m_PreSubImg.center = CGPointMake(m_PreSubImgPanel.frame.size.width/2, m_PreSubImgPanel.frame.size.height/2);
        m_PreSubImg.layer.shadowOpacity = 1.0;
        m_PreSubImg.layer.shadowOffset  = CGSizeMake(3, 3);
        m_PreSubImg.layer.shadowColor   = [[UIColor blackColor] CGColor];
        [m_PreSubImgPanel addSubview:m_PreSubImg];
        [m_PreSubImg release];
        
        UIButton *subbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        subbtn.frame = temp.frame;
        [subbtn addTarget:self action:@selector(HiddenSubImgPanel:) forControlEvents:UIControlEventTouchUpInside];
        [m_PreSubImgPanel addSubview:subbtn];
          
        NSString *str = @"W";
        CGSize size1= [str sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(m_Table.frame.size.width-20, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
        m_FontHeight = size1.height;
    }

    return self;
}

-(void)SetUpSharePanel
{
    m_SharePanel = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    m_SharePanel.backgroundColor = [UIColor clearColor];
    m_SharePanel.alpha = 0.0;
    [self addSubview:m_SharePanel];
    [m_SharePanel release];
    
    UIImageView *back = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, m_SharePanel.frame.size.width, m_SharePanel.frame.size.height)];
    back.image = [UIImage imageNamed:@"sharebg.png"];
    [m_SharePanel addSubview:back];
    [back release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = 0;
    button.frame = CGRectMake(0, 95, 245, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"renren.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
    [m_SharePanel addSubview:button];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = 1;
    button.frame = CGRectMake(68, 172, 245, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"QQblog.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
    [m_SharePanel addSubview:button];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = 2;
    button.frame = CGRectMake(0, 250, 245, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"sina blog.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
    [m_SharePanel addSubview:button];
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(10, 6, 43, 38);
    [button setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    button.tag = 3;
    [button addTarget:self action:@selector(OnShareBtnDown:) forControlEvents:UIControlEventTouchUpInside];
    [m_SharePanel addSubview:button];
}

-(void)OnShareBtnDown:(UIButton*)sender
{
    [self HiddenShare];
    
    if (Logined == [CUser DefaultUser].m_UType)
    {
        if (3 == sender.tag)
        {
            ;//
        }
        //renren
        else if (0 == sender.tag)
        {
            NSString *path = [NSString stringWithFormat:@"%@/tmp/share.jpg", NSHomeDirectory()];
            NSData *data = UIImageJPEGRepresentation(m_Image.image, 1.0);
            [data writeToFile:path atomically:YES];
            [[CMainPageCtrl DefaultMainPageCtrl] OnShareSelected:0];
        }
        //qq
        else if (1 == sender.tag)
        {
            NSString *path = [NSString stringWithFormat:@"%@/tmp/share.jpg", NSHomeDirectory()];
            NSData *data = UIImageJPEGRepresentation(m_Image.image, 1.0);
            [data writeToFile:path atomically:YES];
            [[CMainPageCtrl DefaultMainPageCtrl] OnShareSelected:1];
        }
        //sina
        else if (2 == sender.tag)
        {
            NSString *path = [NSString stringWithFormat:@"%@/tmp/share.jpg", NSHomeDirectory()];
            NSData *data = UIImageJPEGRepresentation(m_Image.image, 1.0);
            [data writeToFile:path atomically:YES];
            [[CMainPageCtrl DefaultMainPageCtrl] OnShareSelected:2];
        }
        else {;}
    }
    else 
    {
        /*UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登陆" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alter show];
        [alter autorelease];*/
        
        [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:2]];
        
        [[CRootCtrlManager DefaultRootCtrl] HiddenComEditView];
    }
}

-(void)ShowShare
{
    [UIView beginAnimations:nil context:nil];
    m_SharePanel.alpha = 1.0;
    [UIView commitAnimations];
}

-(void)HiddenShare
{
    [UIView beginAnimations:nil context:nil];
    m_SharePanel.alpha = 0.0;
    [UIView commitAnimations];
}

-(void)ResetComEditView
{
    if (m_ComFinishBtn.alpha > 0.0)
    {
        m_Write.m_TextView.text = nil;
        [m_Write.m_TextView resignFirstResponder];
        m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y-m_Write.frame.size.height);
        m_ComFinishBtn.alpha = 0.0;
        [m_Write ResetStars];
    }

    [m_Product CancelSubImgTask];
    
    m_Product.delegate = m_PreItem;
    m_PreItem          = nil;
    m_Product          = nil;
    m_PdtName.text     = nil;
    m_SumContent.text  = nil;
    m_PubName.text     = nil;
    m_ResName.text     = nil;
    m_ResAddr.text     = nil;
    //m_ResName.text     = nil;
    //m_ResAddr.text     = nil;
    //m_Distance.text    = @"0km";
    m_Image.image      = nil;
    m_Icon.image       = nil;
    
    [self RestStars];
    
    [m_DisData removeAllObjects];
    
    [m_Table removeFromSuperview];
    m_Table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, m_Scroll.frame.size.width, 0)];
    m_Table.scrollEnabled = NO;
    m_Table.separatorStyle= UITableViewCellSeparatorStyleNone;
    m_Table.delegate = self;
    m_Table.dataSource=self;
    m_Table.backgroundColor = [UIColor clearColor];
    [m_Scroll addSubview:m_Table];
    [m_Table release];
    
    m_BtnPanel.alpha = 0.0;
    m_Scroll.contentSize = CGSizeMake(m_Scroll.contentSize.width, m_Scroll.frame.size.height+1);
    [m_Scroll setContentOffset:CGPointMake(0, 0)];
    
    m_SuvView.frame = CGRectMake(0, self.frame.size.height-40, self.frame.size.width, ICON_HEIGHT+40);
    m_SuvView.tag = 0;
    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, 2*M_PI, 1.0f, 0.0f, 0.0f);
    m_Drawer.layer.transform = transform;
    [m_SubImgs ResetGallery];
}

-(void)OnPingLunButtonDown:(UIButton*)sender
{
    //
}

-(void)OnBackButtonDown:(UIButton*)sender
{
    if (1 == sender.tag)
    {
        if (Logined == [CUser DefaultUser].m_UType)
        {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.5];
            [m_Write.m_Stars ResetStart];
            m_Write.m_Title.text = m_PdtName.text;
            m_Write.m_TextView.text = @"想说些什么...";
            m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y+m_Write.frame.size.height);
            [m_Write.m_TextView becomeFirstResponder];
            [UIView commitAnimations];
            
            m_ComFinishBtn.alpha = 1.0;
        }
        else 
        {
            /*UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登陆..." delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alter show];
            [alter autorelease];*/
            
            [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:2]];
            
            [[CRootCtrlManager DefaultRootCtrl] HiddenComEditView];
        }
    }
    else if (0 == sender.tag)
    {
        [delegate DidComEditClicked:sender.tag Content:nil];
    }
    else if (2 == sender.tag)
    {
        if ([m_Write.m_TextView.text length] > 0 && [m_Write.m_TextView.text length] <= 140)
        {
            CCommentary *com = [[CCommentary alloc] init];
            com.C_Content = m_Write.m_TextView.text;
            com.C_PubNick = [CUser DefaultUser].U_Nick;
            [self AddNewCommetry:com Index:1];
            [m_Table reloadData];
            [com release];
            
            [delegate DidComEditClicked:1 Content:m_Write.m_TextView.text];
        }
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [m_Write.m_Stars ResetStart];
        m_Write.m_TextView.text = nil;
        [m_Write.m_TextView resignFirstResponder];
        m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y-m_Write.frame.size.height);
        [UIView commitAnimations];
        
        m_ComFinishBtn.alpha = 0.0;
    }
    else {;}
}

-(void)AddNewCommenties:(NSArray*)coms
{
    if ([coms count] > 0)
    {
        for (CCommentary *com in coms)
        {
            [self AddNewCommetry:com Index:-1];
        }
    }
    
    m_Scroll.scrollEnabled = YES;
}

-(void)AddNewCommetry:(CCommentary*)com Index:(int)index
{
    if (com)
    {
        UIFont *font = [UIFont systemFontOfSize:DIS_FONTSIZE];
        CGFloat fHeight = [CDisContent GetDicContentHeight:com.C_Content Width:m_Table.frame.size.width-58 Font:font]+10;
        if (fHeight < 62)
            fHeight = 62;
        
        CellData *celldata = [[CellData alloc] initWithCom:com Height:fHeight];
        if (-1 == index)
            [m_DisData addObject:celldata];
        else 
        {
            if ([m_DisData count]>0)
                [m_DisData insertObject:celldata atIndex:index];
            else 
                [m_DisData addObject:celldata];
        }
        [celldata release];
  
        m_Table.frame = CGRectMake(m_Table.frame.origin.x, m_Table.frame.origin.y, m_Table.frame.size.width, m_Table.frame.size.height+fHeight);
        CGFloat fh = m_Table.frame.size.height;
        if (fh > m_Scroll.frame.size.height+1)
            m_Scroll.contentSize = CGSizeMake(m_Scroll.frame.size.width, fh);
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [m_DisData count];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CellData *celldata = [m_DisData objectAtIndex:indexPath.row];
    
    return celldata.m_fHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCellStyle style = UITableViewCellStyleValue1;
	CDisCellView *cell = (CDisCellView*)[tableView dequeueReusableCellWithIdentifier:@"BaseCell"];
    
    if ([m_DisData count] > 0)
    {
        CellData *celldata = [m_DisData objectAtIndex:indexPath.row];
        
        if (nil == cell)
        {
            int dic = (0 == indexPath.row%2) ? (0) : (1);
            cell = [[[CDisCellView alloc] initWithStyle:style reuseIdentifier:@"BaseCell" Size:CGSizeMake(m_Table.frame.size.width, celldata.m_fHeight) IconDic:dic] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        if (!cell.m_Source)
            ((CCommentary*)cell.m_Source).m_ImageView = nil;
        cell.m_Source = celldata.m_Com; 
        
        cell.m_Item.m_Imgae.image = nil;
        cell.m_Item.m_Name.text = celldata.m_Com.C_PubNick;
        cell.m_Item.m_Content.m_Text.numberOfLines = celldata.m_fHeight/m_FontHeight+0.5;
        cell.m_Item.m_Content.m_Text.text = celldata.m_Com.C_Content;
        //writericon
        //////NSLog(@"pubid:%ld", [celldata.m_Com.C_PubID longValue]);
        NSData *data = [celldata.m_Com GetComWriterIcon:[NSString stringWithFormat:@"%@/%ld.jpg", [AppConfig DefaultAppConfig].m_IConsPath, [celldata.m_Com.C_PubID longValue]]];
        if (data)
        {
            cell.m_Item.m_Imgae.image = [UIImage imageWithData:data];
        }
        else 
        {
            celldata.m_Com.m_ImageView = cell.m_Item.m_Imgae;
            cell.m_Item.m_Imgae.image = [UIImage imageNamed:@"dicon.png"];
        }
        
        return cell;  
    }
    
    return nil;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    m_BtnPanel.alpha = 0.0;
    
    //more
    if ((scrollView.contentOffset.y+scrollView.frame.size.height) - scrollView.contentSize.height > 50)
    {
        [self CommentariesWorker:m_Product];
    }
}

-(NSString*)GetDistance:(CProduct*)product Coordinate:(CLLocationCoordinate2D)coordinate
{
    //设置距离
    NSString *message = nil;
    if (NormalSupport == [[CLocator DefaultLocator] CheckDevLocation])
    {
        if ((0.000000 != [product.P_WDu floatValue]) && (0.000000 != [product.P_JDu floatValue]))
        {
            CLLocation *l1 = [[[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude] autorelease];
            CLLocation *l2 = [[[CLLocation alloc] initWithLatitude:[product.P_WDu floatValue] longitude:[product.P_JDu floatValue]] autorelease];

            double dis = [l2 distanceFromLocation:l1]/1000;
            if (dis < 1)
            {
                dis *= 1000;
                dis += 1;
                message = [NSString stringWithFormat:@"%0.0fm", dis];
            }
            else
            {
                message = [NSString stringWithFormat:@"%0.0fkm", dis];
            }
        }
        else 
        {
            message = [NSString stringWithFormat:@"%0.0fm", 1.00000];
        }
    }
    else 
    {
        ////NSLog(@"定位未打开，与美食间的距离为1m。\r\n\r\n");
        message = [NSString stringWithFormat:@"%0.0fm", 1.00000];
    }
    
    m_Distance.text = message;
    
    return message;
}

-(void)SetComEditViewInfoEx:(CProduct*)product
{
    m_Product = product;
    
    if (m_Product)
    {
        m_Product.delegate = self;
        [m_Product ResetQueryConditions];
        m_SumContent.text = m_Product.P_Caption;
        m_PubName.text = m_Product.P_PubName;
        m_PdtName.text = m_Product.P_Name;
        m_ResName.text = m_Product.P_ResName;
        m_ResAddr.text = m_Product.P_Position;
        
        //image
        NSData *data = [m_Product GetProductImage];
        if (data)
        {
            m_Image.image = [UIImage imageWithData:data];
        }
        else 
        {
            m_Image.image = [UIImage imageWithData:[CMainPageCtrl DefaultMainPageCtrl].m_DfData];
        }
        
        //pubicon
        data = [m_Product GetPubIcon];
        if (data)
        {
            m_Icon.image = [UIImage imageWithData:data];
        }
        else 
        {
            m_Icon.image = [UIImage imageNamed:@"dicon.png"];
        }
        
        [self SetLightStars:[m_Product.P_Star intValue]];
        
        if ([m_Product.P_SubImage intValue] > 0)
        {
            NSArray *urls = [m_Product.P_SubImgUrl componentsSeparatedByString:@"||"];
            NSMutableArray *rets = [NSMutableArray array];
            NSData *data = nil;
            CGalleyItem *item = nil;
            UIImage *image = nil;
            for (int i=0; i<[m_Product.P_SubImage intValue]; i++)
            {
                item = [[CGalleyItem alloc] initWithImage:nil];
                data = [m_Product GetSubImage:i];
                if (!data)
                {
                    image = [UIImage imageNamed:@"dicon.png"];
                    [m_Product DownLoadSubImage:[urls objectAtIndex:i] Object:item.m_ImageView Number:[NSNumber numberWithInt:i]];
                }
                else 
                {
                    image = [UIImage imageWithData:data];
                }
                item.m_ImageView.image = image;
                [rets addObject:item];
                [item release];
            }
            
            [m_SubImgs SetItems:rets Item:nil];
            
            m_Drawer.hidden = NO;
        }
        else 
        {
            m_Drawer.hidden = YES;
        }
        
        /*m_ResName.text = m_Product.P_ResName;
         
        [m_DelBtn setTitle:[NSString stringWithFormat:@"好吃 %d", [m_Product.P_Eat intValue]] forState:UIControlStateNormal];
        [m_NiceBtn setTitle:[NSString stringWithFormat:@"好看 %d", [m_Product.P_Nice intValue]] forState:UIControlStateNormal];
        [m_wantBtn setTitle:[NSString stringWithFormat:@"想吃 %d", [m_Product.P_Want intValue]] forState:UIControlStateNormal];
        
        //计算地址的显示宽度
        m_ResAddr.text = m_Product.P_Position;
        CGSize size = [m_ResAddr.text sizeWithFont:m_ResAddr.font constrainedToSize:CGSizeMake(MAXFLOAT, m_ResAddr.frame.size.height)];
        CGFloat fwidth = size.width;
        if (fwidth > (m_PdtName.frame.size.width-10-m_Distance.frame.size.width))
        {
            m_ResAddr.numberOfLines = 2;
            m_ResAddr.frame = CGRectMake(m_ResAddr.frame.origin.x, m_AddCom.frame.origin.y+m_AddCom.frame.size.height-22, m_PdtName.frame.size.width-10-m_Distance.frame.size.width, 25);
            m_ResName.frame = CGRectMake(m_ResName.frame.origin.x, m_ResAddr.frame.origin.y-12, m_ResName.frame.size.width, m_ResName.frame.size.height);
            //距离
            m_Local.frame = CGRectMake(m_ResAddr.frame.origin.x+m_ResAddr.frame.size.width, m_AddCom.frame.origin.y+m_AddCom.frame.size.height-m_Local.frame.size.height, m_Local.frame.size.width, m_Local.frame.size.height);
            m_Distance.frame = CGRectMake(m_Local.frame.origin.x+m_Local.frame.size.width, m_Local.frame.origin.y, m_Distance.frame.size.width, m_Distance.frame.size.height);
        }
        else 
        {
            m_ResAddr.numberOfLines = 1;
            m_ResAddr.frame = CGRectMake(m_ResAddr.frame.origin.x, m_AddCom.frame.origin.y+m_AddCom.frame.size.height-10, fwidth, 10);
            m_ResName.frame = CGRectMake(m_ResName.frame.origin.x, m_ResAddr.frame.origin.y-12, m_ResName.frame.size.width, m_ResName.frame.size.height);
            //距离
            m_Local.frame = CGRectMake(m_ResAddr.frame.origin.x+m_ResAddr.frame.size.width, m_AddCom.frame.origin.y+m_AddCom.frame.size.height-m_Local.frame.size.height, m_Local.frame.size.width, m_Local.frame.size.height);
            m_Distance.frame = CGRectMake(m_Local.frame.origin.x+m_Local.frame.size.width, m_Local.frame.origin.y, m_Distance.frame.size.width, m_Distance.frame.size.height);
        }
        
        CCommentary *com = [[CCommentary alloc] init];
        [com SetCommentaryWithProduct:product];
        NSArray *COMS = [NSArray arrayWithObjects:com, nil];
        [self AddNewCommenties:COMS];
        [m_Table reloadData];
        [com release];*/
    }
}

-(void)SetComEditViewInfo:(CProduct*)product Item:(CPreItem*)item
{
    if (product)
    {
        m_Scroll.scrollEnabled = NO;
        
        m_PreItem = item;
        
        [self SetComEditViewInfoEx:product];
        
        //距离
        m_Distance.text= item.m_Distance.text;
        
        m_Scroll.scrollEnabled = YES;
    }
}

-(void)CommentariesWorker:(id)object
{
    if (object)
    {
        CProduct *product = object;
        [product GetCommentaries];
    }
}

-(void)DidDownLoadSubImage:(id)product Image:(NSData *)image Object:(id)object
{
    if (m_Product == product)
    {
        ((UIImageView*)object).image = [UIImage imageWithData:image];
    }
}

-(void)DidDownLoadPubIcon:(id)product Image:(NSData *)image
{
    if (m_Product == product)
    {
        m_Icon.image = [UIImage imageWithData:image];
    }
}

-(void)DidDownLoadCommentaries:(id)product Commetaries:(NSArray*)coms
{
    if (m_Product == product && m_PreItem)
    {
        for (int i=[coms count]-1; i>=0; i--)
        {
            [self AddNewCommetry:[coms objectAtIndex:i] Index:-1];
        }
        
        if ([coms count] > 0)
        {
            [m_Table reloadData];
        }
    }
}

-(void)DidDownLoadImage:(id)product Image:(NSData*)image
{
    if (m_Product == product)
    {
        m_Image.image = [UIImage imageWithData:image];
    }
}

-(void)DidDownLoadSuccess:(id)product OpType:(int)optype Index:(int)index Info:(NSString *)info
{
    //commitpingjia
    if (3 == optype)
    {
        if (self.frame.size.width/2 == self.center.x)
        {
            CProduct *prdct = product;
            //del
            if (0 == index)
            {
                [m_DelBtn setTitle:[NSString stringWithFormat:@"好吃 %d", [prdct.P_Eat longValue]] forState:UIControlStateNormal];
            }
            //want
            else if (1 == index)
            {
                [m_wantBtn setTitle:[NSString stringWithFormat:@"想吃 %d", [prdct.P_Want longValue]] forState:UIControlStateNormal];
            }
            //nice
            else if (2 == index)
            {
                [m_NiceBtn setTitle:[NSString stringWithFormat:@"好看 %d", [prdct.P_Nice longValue]] forState:UIControlStateNormal];
            }
            else {;}
        }
    }
}

-(void)DidDownLoadError:(id)product OpType:(int)optype
{
    //
}

-(void)DidWriteViewButtonClicked:(UIButton *)sender Object:(id)object
{
    if (1 == sender.tag)
    {
        if ([m_Write.m_TextView.text length] > 0 && [m_Write.m_TextView.text length] <= 140)
        {
            CCommentary *com = [[CCommentary alloc] init];
            com.C_Content = object;
            com.C_PubNick = [CUser DefaultUser].U_Nick;
            [self AddNewCommetry:com Index:1];
            [m_Table reloadData];
            [com release];
            
            [delegate DidComEditClicked:1 Content:m_Write.m_TextView.text];
        }
        
        //星星
        int nCnt = m_Write.m_Stars.m_Slider.frame.size.width/m_Write.m_Stars.m_Width;
        if (nCnt>0)
            [self CommitStarLevel:m_Product Starts:nCnt];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        m_Write.m_TextView.text = nil;
        [m_Write.m_TextView resignFirstResponder];
        m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y-m_Write.frame.size.height);
        [UIView commitAnimations];
        
        m_ComFinishBtn.alpha = 0.0;
    }
}

//stars
-(void)SetLightStars:(int)num
{
    int total = 0;
    
    if (num>0 && num<=100)
    {
        total = 1;
    }
    else if (num>100 && num<=200)
    {
        total = 2;
    }
    else if (num>200 && num<=300)
    {
        total = 3;
    }
    else if (num>300 && num<=400)
    {
        total = 4;
    }
    else if (num > 400)
    {
        total = 5;
    }
    else
    {
        total = 0;
    }
    
    [m_StarsPanel SetLightStartWithNum:total];
}

-(void)RestStars
{
    [m_StarsPanel ResetStart];
    return;
    
    for (UIImageView *star in [m_StarsPanel subviews])
    {
        star.image = [UIImage imageNamed:@"favorite-gray.png"];
    }
}

- (void)OnFavoriteButtonDown:(UIButton*)sender
{
    if (Logined == [CUser DefaultUser].m_UType)
    {
        [[CMainPageCtrl DefaultMainPageCtrl] CommitFavorite:[NSString stringWithFormat:@"%ld", [m_Product.P_AID longValue]]];
    }
    else 
    {
        /*UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登陆" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alter show];
        [alter autorelease];*/
        
        [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:2]];
        
        [[CRootCtrlManager DefaultRootCtrl] HiddenComEditView];
    }
}

//提交星星
- (void)CommitStarLevel:(CProduct*)product Starts:(int)stars
{
    if (product)
    {
        CUser *user = [CUser DefaultUser];
        [product CommitStarsLevel:stars Mobikey:user.U_Token Sessionid:user.U_Session];
    }
}

//好吃，好看，想吃
- (void)OnPingJiaButtonDown:(UIButton*)sender
{
    if (Logined == [CUser DefaultUser].m_UType)
    {
        //0-write
        if (0 == sender.tag)
        {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.5];
            [m_Write.m_Stars ResetStart];
            m_Write.m_Title.text = m_PdtName.text;
            m_Write.m_Icon.image = m_Icon.image;
            m_Write.m_TextView.text = @"想说些什么...";
            m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y+m_Write.frame.size.height);
            [m_Write.m_TextView becomeFirstResponder];
            [UIView commitAnimations];
            
            m_ComFinishBtn.alpha = 1.0;
        }
        //1-commit
        else 
        {
            if ([m_Write.m_TextView.text length] > 0 && [m_Write.m_TextView.text length] <= 140)
            {
                CCommentary *com = [[CCommentary alloc] init];
                com.C_Content = m_Write.m_TextView.text;
                com.C_PubNick = [CUser DefaultUser].U_Nick;
                [self AddNewCommetry:com Index:1];
                [m_Table reloadData];
                [com release];
                
                [delegate DidComEditClicked:1 Content:m_Write.m_TextView.text];
            }
            
            //星星
            CGFloat fstars = m_Write.m_Stars.m_Slider.frame.size.width/m_Write.m_Stars.m_Width;
            if (fstars > 0)
            {
                [self CommitStarLevel:m_Product Starts:fstars];
            }
            
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.5];
            m_Write.m_TextView.text = nil;
            [m_Write.m_TextView resignFirstResponder];
            m_Write.center = CGPointMake(m_Write.center.x, m_Write.center.y-m_Write.frame.size.height);
            [UIView commitAnimations];
            
            m_ComFinishBtn.alpha = 0.0;
        }
    }
    else 
    {
        /*UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登陆..." delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
         [alter show];
         [alter autorelease];*/
        
        [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:2]];
        
        [[CRootCtrlManager DefaultRootCtrl] HiddenComEditView];
    }
    
    /*
    //3-好吃
    //4-好看
    //5-想吃
    
    int type = 0;
    //3-好吃
    if (3 == sender.tag)
        type = 4;
    //4-好看
    else if (4 == sender.tag)
        type = 5;
    //5-想吃
    else if (5 == sender.tag)
        type = 6;
    else {;}
     
    [self CommitPingJia:type];*/
}

- (void)CommitPingJia:(int)index
{
    if (Logined == [CUser DefaultUser].m_UType)
    {
        [m_Product PublicationAppraisal:[CUser DefaultUser].U_Token SessionID:[CUser DefaultUser].U_Session Type:index];
    }
    else 
    {
        /*UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登陆..." delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [alter show];
        [alter autorelease];*/
        
        [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:2]];
        
        [[CRootCtrlManager DefaultRootCtrl] HiddenComEditView];
    }
}

//attentionpanel
-(void)OnAttenButtonDown:(UIButton*)sender
{
    m_Product.delegate = nil;
    m_Product = nil;
    m_PreItem = nil;
    
    //m_BtnPanel.alpha = 1.0;
    //1-sameres
    if (1 == sender.tag)
    {
        [delegate DidSameButtonClicked:sender.tag Title:m_ResName.text];
        
        if (0 != [[CRootCtrlManager DefaultRootCtrl].m_TabBar GetCursor])
        {
            [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:[[CRootCtrlManager DefaultRootCtrl].m_TabBar GetProCursor]]];
            
            //[self performSelector:@selector(DidSameClicked:) withObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:sender.tag], m_ResName.text, nil] afterDelay:0.3];
        }
    }
    //2-samename
    else if (2 == sender.tag)
    {
        [delegate DidSameButtonClicked:sender.tag Title:m_PdtName.text];
        
        if (0 != [[CRootCtrlManager DefaultRootCtrl].m_TabBar GetCursor])
        {
            [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:[[CRootCtrlManager DefaultRootCtrl].m_TabBar GetProCursor]]];
            
            //[self performSelector:@selector(DidSameClicked:) withObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:sender.tag], m_PdtName.text, nil] afterDelay:0.3];
        }
    }
    else{;}
}

-(void)DidSameClicked:(NSArray*)values
{
    int index = [[values objectAtIndex:0] intValue];
    NSString *text = [values objectAtIndex:1];
    
    [delegate DidSameButtonClicked:index Title:text];
}

-(void)OnAttentionSelected:(UIButton*)sender
{
    [self ShowShare];
    /*if (Logined == [CUser DefaultUser].m_UType)
    {
        //people
        if (0 == sender.tag)
        {
            [self CommitPeopleRequest];
        }
        //food
        else if (1 == sender.tag)
        {
            [self CommitFoodRequest];
        }
        //address
        else if (2 == sender.tag)
        {
            [self CommitAddressRequest];
        }
        else {;}
    }
    else 
    {
        UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请先登陆..." delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [suc show];
        [suc autorelease];
        [[CRootCtrlManager DefaultRootCtrl].m_TabBar DidTabBarItemSelected:[[CRootCtrlManager DefaultRootCtrl].m_TabBar.m_Items objectAtIndex:2]];
        
        [[CRootCtrlManager DefaultRootCtrl] HiddenComEditView];
    }
    
    m_BtnPanel.alpha = 0.0;*/
}

//people
-(void)CommitPeopleRequest
{
    CUser *user = [CUser DefaultUser];
    NSMutableString *request = [NSMutableString string];
    [request appendFormat:@"action=%@", OP_ADD_ATTENTION];
    [request appendFormat:@"&type=%d", 1];
    [request appendFormat:@"&mobikey=%@", user.U_Token];
    [request appendFormat:@"&sessionid=%@", user.U_Session];
    [request appendFormat:@"&value=%ld", [m_Product.P_Publisher longValue]];
    
    ////NSLog(@"\r\n\r\n关注人:%@\r\n\r\n", request);
    
    [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_ATTENTION_PEOPLE Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithInt:0] MType:Post UserInfo:m_Product.P_Publisher];
}

-(void)ReceivePeopleResponse:(NSDictionary *)data
{
    ////NSLog(@"\r\n\r\n收到关注人结果:%@___%@\r\n\r\n", data, [data objectForKey:@"Msg"]);
    
    if (0 == [[data objectForKey:@"Msg_error"] intValue])
    {
        UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加关注成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [suc show];
        [suc autorelease];
    }
    else 
    {
        UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已经关注过了" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [suc show];
        [suc autorelease];
    }
}

//food
-(void)CommitFoodRequest
{
    CUser *user = [CUser DefaultUser];
    NSMutableString *request = [NSMutableString string];
    [request appendFormat:@"action=%@", OP_ADD_ATTENTION];
    [request appendFormat:@"&type=%d", 2];
    [request appendFormat:@"&mobikey=%@", user.U_Token];
    [request appendFormat:@"&sessionid=%@", user.U_Session];
    [request appendFormat:@"&value=%@", m_Product.P_Name];
    
    ////NSLog(@"\r\n\r\n关注美食:%@\r\n\r\n", request);
    
    [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_ATTENTION_FOOD Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithInt:1] MType:Post UserInfo:m_Product.P_AID];
}

-(void)ReceiveFoodResponse:(NSDictionary *)data
{
    ////NSLog(@"\r\n\r\n收到关注美食结果:%@___%@\r\n\r\n", data, [data objectForKey:@"Msg"]);
    
     if (0 == [[data objectForKey:@"Msg_error"] intValue])
     {
         UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加关注成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
         [suc show];
         [suc autorelease];
     }
     else 
     {
         UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已经关注过了" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
         [suc show];
         [suc autorelease];
     }
}

//address
-(void)CommitAddressRequest
{
    CUser *user = [CUser DefaultUser];
    NSMutableString *request = [NSMutableString string];
    [request appendFormat:@"action=%@", OP_ADD_ATTENTION];
    [request appendFormat:@"&type=%d", 3];
    [request appendFormat:@"&mobikey=%@", user.U_Token];
    [request appendFormat:@"&sessionid=%@", user.U_Session];
    [request appendFormat:@"&value=%@", m_Product.P_Position];
    [request appendFormat:@"&x=%f", [m_Product.P_WDu floatValue]];
    [request appendFormat:@"&y=%f", [m_Product.P_JDu floatValue]];
    
    ////NSLog(@"\r\n\r\n关注地方:%@\r\n\r\n", request);
    
    [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_ATTENTION_ADDRESS Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithInt:2] MType:Post UserInfo:m_Product.P_Position];
}

-(void)ReceiveAddressResponse:(NSDictionary *)data
{
    ////NSLog(@"\r\n\r\n收到关注地方结果:%@___%@\r\n\r\n", data, [data objectForKey:@"Msg"]);
    
     if (0 == [[data objectForKey:@"Msg_error"] intValue])
     {
         UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"添加关注成功" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
         [suc show];
         [suc autorelease];
     }
     else 
     {
         UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已经关注过了" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
         [suc show];
         [suc autorelease];
     }
}

-(void)OnDrawerDown:(UIButton*)sender
{
    if (0 == m_SuvView.tag)
    {
        [self ShowSubImgsPanel];
    }
    else 
    {
        [self HiddenSubImgsPanel];
    }
}

-(void)ShowSubImgsPanel
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    m_SuvView.tag = 1;
    m_SuvView.center = CGPointMake(m_SuvView.center.x, m_SuvView.center.y-ICON_HEIGHT);
    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, M_PI, 1.0f, 0.0f, 0.0f);
    m_Drawer.layer.transform = transform;
    [UIView commitAnimations];
    
    //[m_Drawer setBackgroundImage:[UIImage imageNamed:@"button-more-d.png"] forState:UIControlStateNormal];
}

-(void)HiddenSubImgsPanel
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    m_SuvView.tag = 0;
    m_SuvView.center = CGPointMake(m_SuvView.center.x, m_SuvView.center.y+ICON_HEIGHT);
    CATransform3D transform = CATransform3DIdentity;
    transform = CATransform3DRotate(transform, 2*M_PI, 1.0f, 0.0f, 0.0f);
    m_Drawer.layer.transform = transform;
    [UIView commitAnimations];
    
    //[m_Drawer setBackgroundImage:[UIImage imageNamed:@"button-more.png"] forState:UIControlStateNormal];
}

-(void)DidGallerySelected:(int)index Directory:(int)directory Object:(id)object
{
    CGalleyItem *item = [[m_SubImgs.m_RootPanel subviews] objectAtIndex:index];
    m_PreSubImg.image = item.m_ImageView.image;
    
    [UIView beginAnimations:nil context:nil];
    m_PreSubImgPanel.alpha = 1.0;
    [UIView commitAnimations];
}

-(void)HiddenSubImgPanel:(UIButton*)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(DidSubImgPanelHidden)];
    m_PreSubImgPanel.alpha = 0.0;
    [UIView commitAnimations];
}

-(void)DidSubImgPanelHidden
{
    m_PreSubImg.image = nil;
}

-(void)DidGalleryTurnPage:(int)index Directory:(int)directory Object:(id)object
{
    //
}

-(void)DidGalleryBottom:(id)object
{
    //
}

-(void)DidGalleryDragEnd:(id)object
{
    //
}

//request
-(void)DidOperationFinished:(COperation *)op Data:(NSData *)data Other:(id)other UserInfo:(id)userinfo
{
    int type = [other intValue];
    NSString      *json = nil;
    NSDictionary  *dic  = nil;

    //people
    if (0 == type)
    {
        if ([m_Product.P_Publisher longValue] == [userinfo longValue])
        {
            json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            dic  = [json JSONValue];
            [self ReceivePeopleResponse:dic];
        }
    }
    //food
    else if (1 == type)
    {
        if ([m_Product.P_AID longValue] == [userinfo longValue])
        {
            json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            dic  = [json JSONValue];
            [self ReceiveFoodResponse:dic];
        }
    }
    //address
    else if (2 == type)
    {
        if ([m_Product.P_Position isEqualToString:userinfo])
        {
            json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            dic  = [json JSONValue];
            [self ReceiveFoodResponse:dic];
        }
    }
    else {;}
}

-(void)DidOperationError:(COperation *)op Error:(NSError *)error Other:(id)other UserInfo:(id)userinfo
{
    int type = [other intValue];
    
    //people
    if (0 == type)
    {
        if ([m_Product.P_Publisher longValue] == [userinfo longValue])
        {
            //
        }
    }
    //food
    else if (1 == type)
    {
        if ([m_Product.P_AID longValue] == [userinfo longValue])
        {
            //
        }
    }
    //address
    else if (2 == type)
    {
        if ([m_Product.P_City isEqualToString:userinfo])
        {
            //
        }
    }
    else {;}
}

-(void)DidOperationTimeOut:(COperation *)op Other:(id)other UserInfo:(id)userinfo
{
    int type = [other intValue];
    
    //people
    if (0 == type)
    {
        if ([m_Product.P_Publisher longValue] == [userinfo longValue])
        {
            //
        }
    }
    //food
    else if (1 == type)
    {
        if ([m_Product.P_AID longValue] == [userinfo longValue])
        {
            //
        }
    }
    //address
    else if (2 == type)
    {
        if ([m_Product.P_City isEqualToString:userinfo])
        {
            //
        }
    }
    else {;}
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    m_BtnPanel.alpha = 0.0;
}

@end
